//
// Created by admin on 2018/12/20.
//

#include <iostream>
#include <thread>
#include <chrono>

#include "double_queue.h"
#include "thread_group.h"

struct Test {
    int i = 1;
    void Add(int a) {
      i += a;
    }
};

int main() {
    int k= 100;
    while (k--) {
        std::vector<Test> add_list(3);
        std::vector<DoubleQueue<int>> task_q(3);
        for (size_t i = 0; i < task_q.size(); i++) {
            task_q[i].SetConsumeMsgHandler(std::bind(&Test::Add, &add_list[i], std::placeholders::_1));
        }

        ThreadGroup thread_group;
        for (size_t i = 0; i < task_q.size(); i++) {
            thread_group.AddTaskTick(std::bind(&DoubleQueue<int>::OnProc, &task_q[i]));
        }

        for (int i = 0; i < 100000; i++) {
            for (auto &q : task_q) {
                q.AddMsg(i);
            }
        }

        thread_group.StopAll();
        for (const auto &t : add_list) {
            std::cout << t.i << std::endl;
        }
    }
    return 0;
}